<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let p = new Promise((resolve, reject) => {
            let count = Math.floor(Math.random() * 10);

            setTimeout(() => {
                console.log(count);
                if (count % 2 == 0) {
                    resolve("success");
                } else {
                    reject("fail");
                }
            }, 500);
        })

        /*     p.then(res => {
                console.log(res);
                return new Promise((resolve, reject) => {
                    setTimeout(() => {
                        let num = Math.floor(Math.random() * 10);
                        num >= 3 ? resolve(`second Promise successed, the num is bigger than 3, num is ${num}`) : reject(`second Promise failed, the num is small than 3, num is ${num}`)
                    }, 1000)
                })
            })
                .then(res1 => {
                    console.log(res1)
                })
    
                .catch(err => {
                    console.log(`catch: ${err}`)
                }) */

        /*      p.then(res => {
                 console.log(res)
                 return new Promise((resolve, reject) => {
                     setTimeout(() => {
                         let count = Math.random() * 10
                         count > 5 ? resolve(`second success`) : reject(`second fail`)
                     }, 1000)
                 })
             })
                 .then(res => {
                     console.log(res)
                 })
                 .catch(err => {
                     console.log(err)
                 }) */

        p.then(res => {
            console.log(res)

            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    let count = Math.random() * 10
                    count > 5 ? resolve(`second success ${count}`) : reject(`second fail ${count}`)
                }, 1000)
            })

        }).then(res => {
            console.log(res)
        }).catch(err => {
            console.log(err)
        })
    </script>
</body>

</html>